package com.rw.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author rabit
 */
public class ContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //创建IOC容器的步骤放到这个位置
        String path = sce.getServletContext().getInitParameter("contextConfigLocation");
        System.out.println(path);
        ApplicationContext ac = new ClassPathXmlApplicationContext(path);
        sce.getServletContext().setAttribute("ac",ac);
        System.out.println("初始化上下文的方法执行");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("销毁上下文的方法");
    }
}
